home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / gemfsc20 / gemfsc20.lzh / GEMFUNCS / OBJMXUD.C < prev    next >
C/C++ Source or Header  |  1993-02-01  |  2KB  |  64 lines

  1. /**************************************************************************
  2.  * OBJMXUD.C - Turn a normal object into an XUSERDEF object.
  3.  *
  4.  *    Whenever a library routine wants to supply a custom drawing routine
  5.  *    for a standard GEM object, it calls this to fill in an XUSERDEF
  6.  *    and attach it to the original object.  The difference between an
  7.  *    XUSERDEF object and a regular USERDEF object is the contents of the
  8.  *    USERBLK structure attached to the object.  A regular USERBLK contains
  9.  *    a pointer to the drawing routine followed by a longword of anything
  10.  *    the application wants.    For an XUSERBLK, the ap-specific longword is
  11.  *    a pointer to the XUSERBLK itself, and then there are more fields,
  12.  *    which contain the original ob_type and the original _Ob_spec, the
  13.  *    parent tree and object to which the XUSERBLK is attached, and any
  14.  *    other data you might want to add following the predefined fields.
  15.  *    (When adding other fields after the predefined ones, pass a non-zero
  16.  *    xub_size parm to indicate how much extra data is there.)
  17.  *
  18.  *    All this smoke-and-mirrors lets us transform a standard GEM object
  19.  *    into a new custom type without losing the information from the
  20.  *    original object.  Other library routines (rsc_gstrings, for example)
  21.  *    know how to cope with XUSERBLK objects.
  22.  *
  23.  *    Note that we properly cope with INDIRECT objects (as always), and
  24.  *    we preserve any extended type info in the original object; we only
  25.  *    change the low-order byte when plugging in the G_USERDEF ob_type.
  26.  *************************************************************************/
  27.  
  28. #include "gemfintl.h"
  29.  
  30. void obj_mxuserdef(ptree, obj, pblk, pdraw, ptouch, xub_size)
  31.     OBJECT            *ptree;
  32.     short            obj;
  33.     XUSERBLK        *pblk;
  34.     XUB_DRAWFUNC    *pdraw;
  35.     XUB_TOUCHFUNC    *ptouch;
  36.     long            xub_size;
  37. {
  38.     _Ob_spec_t    *pspec;
  39.     OBJECT        *pobj;
  40.  
  41.     pobj  = &ptree[obj];
  42.     pspec = &pobj->_Ob_spec;
  43.     if (pobj->ob_flags & INDIRECT) {
  44.         pspec = (_Ob_spec_t *)*pspec;
  45.     }
  46.  
  47.     pblk->ub_draw        = pdraw;
  48.     pblk->ub_touch        = ptouch;
  49.     pblk->ub_self        = pblk;
  50.     pblk->ub_size        = (xub_size == 0) ? sizeof(XUSERBLK) : xub_size;
  51.     pblk->parent_tree    = ptree;
  52.     pblk->parent_obj    = obj;
  53.     pblk->ob_type        = pobj->ob_type & 0x00FF;
  54.     pobj->ob_type        = G_USERDEF | (pobj->ob_type & 0xFF00);
  55.  
  56.     if (ptouch != NULL) {
  57.         pobj->ob_flags |= TOUCHEXIT;
  58.     }
  59.  
  60.     pblk->ob_spec = *pspec;
  61.     *pspec          = (_Ob_spec_t)pblk;
  62. }
  63.  
  64.